﻿package mortal.game.manager.msgTip
{
    import Message.Public.*;
    import com.gengine.utils.pools.*;
    import flash.display.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.view.chat.*;
    import mortal.mvc.core.*;

    public class MsgSpeakerImpl extends Sprite
    {
        private var _noticesArr:Array;
        private var _itemShowing:Boolean = false;
        private var _infoArr:Array;
        private var _currentItem:SpeakerItem;

        public function MsgSpeakerImpl()
        {
            this._noticesArr = [];
            this._infoArr = [];
            this.mouseEnabled = false;
            Dispatcher.addEventListener(EventName.ChatResize, this.onResize);
            return;
        }// end function

        private function onNoticeHide(param1:SpeakerItem) : void
        {
            var _loc_2:Boolean = false;
            this._noticesArr.shift();
            this._infoArr.shift();
            removeChild(param1);
            param1.dispose();
            ObjectPool.disposeObject(param1, SpeakerItem);
            this._itemShowing = false;
            if (this._noticesArr.length > 0)
            {
                this._itemShowing = true;
                _loc_2 = true;
                this._currentItem = this._noticesArr[0];
                addChild(this._noticesArr[0]);
                this._noticesArr[0].init(this._infoArr[0].miniPlayer, this._infoArr[0].content, this._infoArr[0].type);
                this._noticesArr[0].updateData(this.onNoticeHide, _loc_2);
                this.setPxy();
            }
            else
            {
                this._currentItem = null;
            }
            return;
        }// end function

        public function removeSpeakerNotice(param1:SEntityId) : void
        {
            var _loc_3:* = undefined;
            var _loc_4:SMiniPlayer = null;
            var _loc_2:* = this._infoArr.length - 1;
            while (_loc_2 >= 0)
            {
                
                _loc_3 = this._infoArr[_loc_2];
                _loc_4 = this._infoArr[_loc_2].miniPlayer;
                if (EntityUtil.equal(_loc_4.entityId, param1))
                {
                    this._infoArr.splice(_loc_2, 1);
                    this._noticesArr.splice(_loc_2, 1);
                }
                _loc_2 = _loc_2 - 1;
            }
            if (this._currentItem && this._currentItem.miniPlayer && EntityUtil.equal(this._currentItem.miniPlayer.entityId, param1))
            {
                this.onNoticeHide(this._currentItem);
            }
            return;
        }// end function

        public function showSpeakerNotice(param1:SMiniPlayer, param2:String, param3:MsgTypeImpl) : void
        {
            var _loc_4:Boolean = false;
            var _loc_5:SpeakerItem = null;
            _loc_5 = ObjectPool.getObject(SpeakerItem);
            this._noticesArr.push(_loc_5);
            this._infoArr.push({miniPlayer:param1, content:param2, type:param3});
            if (!this._itemShowing)
            {
                this._itemShowing = true;
                _loc_4 = true;
                this._currentItem = _loc_5;
                _loc_5.init(param1, param2, param3);
                _loc_5.updateData(this.onNoticeHide, _loc_4);
                addChild(_loc_5);
                this.setPxy();
            }
            return;
        }// end function

        protected function onResize(event:DataEvent) : void
        {
            this.setPxy();
            return;
        }// end function

        public function setPxy() : void
        {
            var _loc_1:SpeakerItem = null;
            _loc_1 = this._noticesArr[0];
            if (_loc_1)
            {
                _loc_1.x = 0;
                _loc_1.y = (GameController.chat.view as ChatModule).y - (GameController.chat.view as ChatModule).getTotalHeight() - 84;
            }
            return;
        }// end function

    }
}
